import 'package:flutter/material.dart';
import 'package:flutter_menu/app_config.dart';
import 'package:flutter_menu/biz/order/order_pg.dart';
import 'package:flutter_menu/data/base_provider.dart';
import 'package:flutter_menu/data/provider/formula_provider.dart';
import 'package:flutter_menu/data/provider/option_material_provider.dart';
import 'package:flutter_menu/model/formula_model.dart';
import 'package:flutter_menu/model/material_model.dart';
import 'package:flutter_menu/model/menu_model.dart';
import 'package:flutter_menu/model/product_model.dart';
import 'package:flutter_menu/model/shope_model.dart';
import 'package:flutter_menu/objectbox.g.dart';
import 'package:get/get.dart';

class DeptProvider extends BaseProvider<DeptModel> {
  DeptProvider(super.store);

  DeptModel? defaultDept;

  ///根据类型查询部门 部门类型 1 普通 2 厨房 3 仓库
  List<DeptModel> getDepartmentByType(int type) {
    return box
        .query(DeptModel_.type.equals(type))
        .order(DeptModel_.sort)
        .build()
        .find();
  }

  DeptModel? loadById(String id) {
    return box.query(DeptModel_.id.equals(id)).build().findFirst();
  }

  ///  根据id查找仓库,没有则返回主仓库
  /// @param id
  /// @return
  DeptModel? loadByIdOrDefault(String? id) {
    if (id == null || id.isEmpty) return getDefault();
    return loadById(id);
  }

  ///  获取默认主仓库
  /// @return
  DeptModel? getDefault() {
    defaultDept ??=
        box.query(DeptModel_.isDefault.equals(1)).build().findFirst();
    return defaultDept;
  }
}
